﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEditor;

namespace Unity
{
    public class Platform
    {
        private string size;
        private string location;

        public string Size
        {
            set
            {
                size = value;
            }
            get
            {
                return size;
            }
        }

        public string Location
        {
            set
            {
                location = value;
            }
            get
            {
                return location;
            }
        }

        private PlatformsProbability platProb;

		public Platform GetPlatform()
		{
			Platform pl = PlatformCreationScript.plats.First ();
			PlatformCreationScript.plats.Remove (pl);
			return pl;
		}

        public void InitializePlatform()
        {
            platProb = new PlatformsProbability();
            platProb.InitializePlatformSize();
            platProb.InitializePlatformLocation();
        }

        public List<Platform> CreatePlatforms(int platformCount)
        {
            return platProb.CreatePlatforms(platformCount);
        }

        public void ChangeLevelSize(double first, double second, double third, double fourth)
        {
            platProb.ChangeLevelSize(first, second, third, fourth);
        }
    }

    public class PlatformsProbability
    {
        private ProbabilitySelection probSelectionSize;
        private double firstPlatform = 1;
        private double secondPlatform = 0;
        private double thirdPlatform = 0;
        private double fourthPlatform = 0;

        private ProbabilitySelection probSelectionLocation;
        private double firstLocation = 0.34;
        private double secondLocation = 0.33;
        private double thirdLocation = 0.33;

        public ProbabilitySelection ProbSelectionSize
        {
            set
            {
                probSelectionSize = value;
            }
            get
            {
                return probSelectionSize;
            }
        }

        public ProbabilitySelection ProbSelectionLocation
        {
            set
            {
                probSelectionLocation = value;
            }
            get
            {
                return probSelectionLocation;
            }
        }

        public void InitializePlatformSize()
        {
            probSelectionSize = new ProbabilitySelection();
            ChangeLevelSize(firstPlatform, secondPlatform, thirdPlatform, fourthPlatform);
        }

        public void InitializePlatformLocation()
        {
            probSelectionLocation = new ProbabilitySelection();
            probSelectionLocation.CreateProbObjectForList(1, "1", firstLocation);
            probSelectionLocation.CreateProbObjectForList(2, "2", secondLocation);
            probSelectionLocation.CreateProbObjectForList(3, "3", thirdLocation);
        }

        public List<Platform> CreatePlatforms(int platformCount)
        {
            List<Platform> platforms = new List<Platform>();
			System.Random rnd = new System.Random();
            for (int iCount = 0; iCount < platformCount; iCount++)
            {
                Platform plat = new Platform();
                plat.Size = probSelectionSize.RandomizeProbabilitySelection(rnd);
                plat.Location = probSelectionLocation.RandomizeProbabilitySelection(rnd);
                platforms.Add(plat);
            }
            return platforms;
        }

        public void ChangeLevelSize(double first, double second, double third, double fourth)
        {
            probSelectionSize.ProbabilityList = new List<ProbabilityObject>();
            probSelectionSize.CreateProbObjectForList(1, "1", first);
            probSelectionSize.CreateProbObjectForList(2, "2", second);
            probSelectionSize.CreateProbObjectForList(3, "3", third);
            probSelectionSize.CreateProbObjectForList(4, "4", fourth);
        }
    }
}
